﻿using System;
using System.Collections.Generic;
using System.Text;
using Mono.Data.Sqlite;
using System.Data;

namespace Rebides
{
    public class Database
    {
        private String _dbName;
        private IDbConnection _dbConn;
        private IDbCommand _dbCmd;
        private IDataReader _reader;
        public Database(string dbName)
        {
            this._dbName = dbName;
        }

        public void OpenDatabase()
        {
            _dbConn = (IDbConnection)new SqliteConnection("URI=file:" + this._dbName);
            _dbConn.Open();
        }

        public IDataReader ExecuteQuery(string query)
        {
            this._dbCmd = _dbConn.CreateCommand();
            this._dbCmd.CommandText = query;
            this._reader = this._dbCmd.ExecuteReader();
            return _reader;
        }

        public void CloseReader()
        {
            this._reader.Dispose();
            this._reader.Close();
        }
        public void CloseDatabase()
        {
            this._dbConn.Close();
        }
    }
}
